import {BasicColumn, FormSchema} from '/@/components/Table';
import {h} from 'vue';
import {render} from '/@/utils/common/renderUtils';
import {DescItem} from '/@/components/Description/index';
import PayNode from './PayNode.vue';
import {formatToDateTime} from '/@/utils/dateUtil';

export const columns: BasicColumn[] = [
  {
    title: '支付金额',
    width: 80,
    fixed: 'left',
    dataIndex: 'payAmount',
    customRender: ({text}) => {
      return text + '元'
    }
  },
  {
    title: '退款金额',
    width: 80,
    dataIndex: 'refundAmount',
    customRender: ({text}) => {
      return text + '元'
    }
  },
  {
    title: '手续费',
    width: 80,
    dataIndex: 'mchFeeAmount',
    customRender: ({text}) => {
      return text + '元'
    }
  },
  {
    title: '商户名称',
    width: 130,
    dataIndex: 'mchName',
  },

  {
    title: '订单号',
    width: 210,
    dataIndex: 'orderNo',
    slots: { customRender: 'orderNo' }
  },

  {
    title: '支付状态',
    width: 100,
    dataIndex: 'status',
    customRender: ({text}) => {
      let color = "green"
      if (text == '0') color = '#fdcb6e'
      if (text == '1') color = '#FFCC33'
      if (text == '2') color = 'green'
      if (text == '3') color = '#FF6666'
      if (text == '4') color = '#FFCC99'
      if (text == '5') color = '#99CCFF'
      if (text == '6') color = '#33CC33'
      
      return render.renderTag(render.renderDict(text, 'pay_order_status'), color)
    }
  },
  
  {
    title: '支付方式',
    width: 120,
    dataIndex: 'wayName',
  },

  {
    title: '回调状态',
    width: 100,
    dataIndex: 'notifyStatus',
    customRender: ({text}) => {
      let color = "green"
      if (text == '0') color = '#fcbe97'
      if (text == '1') color = '#badc58'
      
      return render.renderTag(render.renderDict(text, 'pay_notify_status'), color)
    }
  },

  {
    title: '创建时间',
    width: 160,
    customRender: ({text}) => {
      return formatToDateTime(Number(text))
    },
    dataIndex: 'createdAt',
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'unionOrderNo',
    label: '订单号',
    component: 'Input',
    componentProps: {
      placeholder:'支付/商户/渠道订单号'
    },
    // colProps: {span: 6},
  },
  {
    label: '订单状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'pay_order_status',
      placeholder:'请选择订单状态'
    },
    // colProps: {span: 6},
  },
  {
    label: '回调状态',
    field: 'notifyStatus',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'pay_notify_status',
      placeholder:'请选择回调状态'
    },
    // colProps: {span: 6},
  },
  {
    label: '商户号',
    field: 'mchNo',
    component: 'Input',
    // colProps: {span: 6},
  },
  {
    label: '应用ID',
    field: 'appId',
    component: 'Input',
    // colProps: {span: 6},
  },

  {
    field: 'fieldTime',
    component: 'RangePicker',
    label: '创建时间',
    componentProps: {
      valueType: 'Date',
    },
    colProps: { span: 12},
  },
];

export const refundFormSchema: FormSchema[] = [
  {
    field: 'refundAmount',
    label: '退款金额(元)',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入退款金额',
    }
  },
  {
    field: 'refundReason',
    label: '退款原因',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入退款原因',
    }
  },
]


export const formDetailSchema : DescItem[] = [
  {
    field: 'mchTypeValue',
    label: '所属系统',
    span: 2
  },
  {
    field: 'isvNo',
    label: '服务商号',
    span: 2
  },
  {
    field: 'payOrderNo',
    label: '支付订单号',
    span: 2
  },
  {
    field: 'mchNo',
    label: '商户号',
    span: 2
  },
  {
    field: 'mchOrderNo',
    label: '商户订单号',
    span: 2
  },
  {
    field: 'mchName',
    label: '商户名称',
    span: 2
  },
  {
    field: 'payAmount',
    label: '支付金额',
    span: 2
  },
  {
    field: 'mchFeeRate',
    label: '手续费',
    render: (curVal, data) => {
      let color = '#fd9644'
      if (!curVal) {
        curVal = 0
      }
      return render.renderTag(curVal, color)
    },
    span: 2
  },
  {
    field: 'mchFeeRate',
    label: '商家费率',
    render: (curVal, data) => {
      let color = '#ffbe76'
      if (!curVal) {
        curVal = 0
      }
      return render.renderTag(curVal + '%', color)
    },
    span: 2
  },
  {
    field: 'status',
    label: '订单状态',
    render: (curVal, data) => {
      let color = "green"
      if (curVal == '1') color = '#FFCC33'
      if (curVal == '2') color = 'green'
      if (curVal == '3') color = '#FF6666'
      if (curVal == '4') color = '#FFCC99'
      if (curVal == '5') color = '#99CCFF'
      if (curVal == '6') color = '#33CC33'
      if (curVal == '7') color = '#CC3333'   
      return render.renderTag(render.renderDict(curVal, 'pay_order_status'), color)
    },
    span: 2
  },
  {
    field: 'notifyStatus',
    label: '回调状态',
    span: 2,
    render: (curVal, data) => {
      let color = "green"
      if (curVal == '0') color = '#fcbe97'
      if (curVal == '1') color = '#badc58'
      
      return render.renderTag(render.renderDict(curVal, 'pay_notify_status'), color)
    },
  },
  {
    field: 'appId',
    label: '应用APPID',
    span: 2
  },
  {
    field: 'errCode',
    label: '支付错误码',
    span: 2
  },
  {
    field: 'errMsg',
    label: '支付错误描述',
    span: 2
  },
  {
    field: 'expiredTime',
    label: '订单失效时间',
    render: (curVal, data) => {
      return formatToDateTime(Number(curVal))
    },
    span: 2
  },
  {
    field: 'successTime',
    label: '支付成功时间',
    render: (curVal, data) => {
      return formatToDateTime(Number(curVal))
    },
    span: 2
  },
  {
    field: 'createdAt',
    label: '创建时间',
    render: (curVal, data) => {
      return formatToDateTime(Number(curVal))
    },
    span: 2
  },
  {
    field: 'updatedAt',
    label: '更新时间',
    render: (curVal, data) => {
      return formatToDateTime(Number(curVal))
    },
    span: 4
  },
  {
    field: 'divider-1',
    label: '',
    render: (curVal, data) => {
      return render.renderDivider()
    },
    span: 4
  },

  {
    field: 'goodsSubject',
    label: '商品标题',
    span: 2,
  },
  {
    field: 'goodsBody',
    label: '商品描述',
    span: 2
  },

  {
    field: 'ifCode',
    label: '接口代码',
    span: 2
  },

  {
    field: 'currency',
    label: '货币代码',
    span: 2
  },

  {
    field: 'wayCode',
    label: '支付方式',
    span: 2
  },

  {
    field: 'clientIp',
    label: '客户端IP',
    span: 2
  },

  {
    field: 'channelUser',
    label: '渠道用户标识',
    span: 2
  },

  {
    field: 'channelOrderNo',
    label: '渠道订单号',
    span: 2
  },

  {
    field: 'notifyUrl',
    label: '异步通知地址',
    span: 2
  },

  {
    field: 'returnUrl',
    label: '页面跳转地址',
    span: 2
  },

  {
    field: 'refundStatus',
    label: '退款状态',
    render: (curVal, data) => {
      let color = "green"
      if (curVal == '0') color = '#81ecec'
      if (curVal == '1') color = '#ff7f50'
      if (curVal == '2') color = '#fab1a0'
      
      return render.renderTag(render.renderDict(curVal, 'pay_order_refund_status'), color)
    },
    span: 2
  },

  {
    field: 'refundTimes',
    label: '退款次数',
    span: 2
  },

  {
    field: 'refundAmount',
    label: '退款总额',
    span: 4
  },

  {
    field: 'extParam',
    label: '商户扩展参数',
    span: 4
  },
  {
    field: 'divider-2',
    label: '',
    render: (curVal, data) => {
      return render.renderDivider()
    },
    span: 4
  },
  {
    field: 'tradeType',
    label: '交易类型',
    span: 4
  },
  {
    field: 'tradeContent',
    label: '交易内容',
    span: 4
  },

  {
    field: 'divider-3',
    label: '',
    render: (curVal, data) => {
      return render.renderDividerWithValue('支付数据节点')
    },
    span: 4
  },
  {
    field: 'payNode',
    label: '',
    render: (curVal, data) => {
      console.log("payOrderNo", data.payOrderNo);
      return h(PayNode, {payOrderNo: data.payOrderNo})
    },
    span: 4
  },
];
